﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebPartControls_PictureNewsControl : System.Web.UI.UserControl
{
    int PictureID;
    protected void Page_Load(object sender, EventArgs e)
    {
        NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
        var ds = from news in dc.News
                 join news_to_catalog in dc.NewsToCatalogs
                 on news.News_id equals news_to_catalog.News_id
                 where news_to_catalog.Catalog_id.Equals(1) && news.isPublished.Equals(1)
                 orderby news.Time descending
                 select new
                 {
                     id = news.News_id,
                     标题 = news.Title,
                     内容 = news.Content
                 };

        foreach (var news in ds.Take(1))
        {
            string News_Content;
            HotNews_Title.Text = Convert.ToString(news.标题);
            News_Content = Convert.ToString(news.内容);
            HotNews_Remarks.Text = News_Content.Substring(0,48);
            var picure = from picture in dc.Pictures
                         where picture.News_id.Equals(news.id)
                         select picture.URL;
            PictureID = news.id;
            foreach (var pic in picure)
            {
                HotNews_Picture.DescriptionUrl = HotNews_Picture.ImageUrl = Convert.ToString(pic);
                HotNews_Picture.AlternateText = "已上传文件";
            }
        }


        dc.Dispose();
    }
    public string SubString(string sString, int nLength)
    {

        if (sString.Length <= nLength)
        {
            return sString;
        }
        string sNewStr = sString.Substring(0, nLength);
        sNewStr = sNewStr + "...";

        return sNewStr;
    }
    protected void TotalTextLinkButton_Click(object sender, EventArgs e)
    {
        Session.Add("News_id",PictureID.ToString());
        Response.Redirect("PictureNews.aspx");
    }
}
